package br.ucb.cm.config.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import br.ucb.cm.board.bean.Location;

public class Config implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private BoardConfig board;
	private List<PieceConfig> pieces;
	private Map<Location, PieceConfig> pieceMap;

	public Config() {
		this.board = new BoardConfig(2, 2);
		this.pieces = new ArrayList<PieceConfig>();
		this.pieceMap = new Hashtable<Location, PieceConfig>();
	}
	
	@SuppressWarnings("unchecked")
	public static void updateConfig(List<Object> configList, Config config){
		switch (configList.size()) {
		case 4:
		case 3:
			config.getPieceMap().clear();
			config.getPieceMap().putAll((Map<Location, PieceConfig>) configList.get(2));
		case 2:
			config.getPieces().clear();
			config.getPieces().addAll((List<PieceConfig>) configList.get(1));
		case 1:
			config.setBoard((BoardConfig) configList.get(0));
		}

	}

	public Map<Location, PieceConfig> getPieceMap() {
		return pieceMap;
	}

	public void setPieceMap(Map<Location, PieceConfig> pieceMap) {
		this.pieceMap = pieceMap;
	}

	public BoardConfig getBoard() {
		return board;
	}

	public void setBoard(BoardConfig board) {
		this.board = board;
	}

	public List<PieceConfig> getPieces() {
		return pieces;
	}

	public void setPieces(List<PieceConfig> pieces) {
		this.pieces = pieces;
	}

	@Override
	public String toString() {
		return "Config [board=" + board + ", pieces=" + pieces + ", pieceMap="
				+ pieceMap + "]";
	}

}
